package com.example.examsystem.config;

import com.example.examsystem.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class DataInitializer implements CommandLineRunner {

    private final UserRepository userRepository;

    @Override
    public void run(String... args) throws Exception {
        // 检查是否已经初始化过数据
        if (userRepository.count() > 0) {
            log.info("数据已存在，跳过初始化");
            return;
        }
        
        log.info("数据库为空，数据将通过 data.sql 自动初始化");
    }
}

